package notification.handler;

import java.util.HashMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class HandlerNotification extends HashMap<String,HandlerMessage> implements Runnable {
	private ExecutorService exec;
	private Semaphore Sem;
	private volatile boolean on=true;
	
	public Semaphore getSem(){
		return Sem;
	}
 
	public HandlerNotification(){
		exec=Executors.newSingleThreadExecutor();
		Sem=new Semaphore();
	}
	
	public void poweroff(){
		exec.shutdown();
		on=false;
	}

	public void run() {
		while(on){
		  try {
				Sem.acquire();
				for(HandlerMessage task: values()) exec.execute(task);
		  } 
		  catch (InterruptedException e) {e.printStackTrace();}
		}
	}
}
